package com.region.common.utils;

import java.util.Random;
import java.util.UUID;

/**
 * Get random string
 *
 * @author liujieyu
 * @time 2023/5/23 23:26
 * @description
 */
public final class RandomUtils {

    public static final char[] SOURCES = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
            'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
            'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};

    private static final Random random = new Random();

    /**
     * Get unique ID
     *
     * @return
     */
    public static String getId() {
        return StringUtils.replace(UUID.randomUUID().toString(), "-", "");
    }

    /**
     * Get a random string of the specified length
     *
     * @param length
     * @return
     */
    public static String getRandomString(int length) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            stringBuilder.append(SOURCES[random.nextInt(SOURCES.length)]);
        }
        return stringBuilder.toString();
    }
}
